package com.taotao.task;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.taotao.common.pojo.BaseResult;
import com.taotao.common.utils.RedisUtils;
import com.taotao.service.ParamService;
import com.taotao.service.TaskService;


/**
 * 设置goods失效
 */
@Controller
public class GoodsInvalidTask {
	
	@Autowired
	TaskService taskService;
	@Autowired
	ParamService paramService;
	
	BaseResult baseResult = new BaseResult();

	@RequestMapping("/api/goodsInvalid")
	@Scheduled(cron = "0 0 23 * * ? ") //每天23点触发
    public void goodsInvalid() {
    	try {
    		boolean lock = RedisUtils.tryGetDistributedLock("lockKey_goodsInvalid", "goodsInvalid", 60000);
			if(lock){
				String param = paramService.getParam("job_GoodsInvalidTask");
	    		if("true".equals(param)){
	    			System.out.println("goodsInvalid执行开始...");
	    			taskService.goodsInvalid();
	        		System.out.println("goodsInvalid执行结束...");
	    		}
				RedisUtils.releaseDistributedLock("lockKey_goodsInvalid", "goodsInvalid");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
}